package d3_UDP2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class Cilent {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //创建客户端对象
        DatagramSocket socket = new DatagramSocket();

        while (true) {
            System.out.println("Enter IP Address");
            String msg = sc.nextLine();
            //创建数据包
            byte[] buf = msg.getBytes();
            DatagramPacket packet = new DatagramPacket(buf, buf.length,InetAddress.getLocalHost(),7894);
            //发送数据
            socket.send(packet);
            if (msg.equals("exit")) {
                System.out.println("Cilent Exit");
                break;
            }
        }

        socket.close();//释放资源
    }
}
